﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Zavand.Web.Mvc.Manana.Framework;

namespace Zavand.Web.Mvc.Manana.FrameworkUnitTests
{
    [TestClass]
    public class BaseRouteTest
    {
        [TestMethod]
        public void GetNameTest()
        {
            var r = new UnitTestRoute1();
            Assert.IsTrue(!string.IsNullOrEmpty(r.GetName()));
        }
        [TestMethod]
        public void GetNameLocalizedTest()
        {
            var r = new UnitTestRoute1();
            Assert.IsTrue(!string.IsNullOrEmpty(r.GetNameLocalized()));
        }
        // ReSharper disable InconsistentNaming
        [TestMethod]
        public void GetName_Different_From_GetNameLocalized_Test()
        // ReSharper restore InconsistentNaming
        {
            var r = new UnitTestRoute1();
            Assert.AreNotEqual(r.GetName(), r.GetNameLocalized());
        }
        [TestMethod]
        public void GetUrlTest()
        {
            var r = new UnitTestRoute1();

            // No area
            r.Controller = "ctrl";
            r.Action = "actn";
            Assert.AreEqual("ctrl/actn", r.GetUrl());

            // With area
            r.Area = "arrrrea";
            Assert.AreEqual("arrrrea/ctrl/actn", r.GetUrl());
        }
        [TestMethod]
        public void GetUrlLocalizedTest()
        {
            var r = new UnitTestRoute1();

            Assert.IsTrue(r.GetUrlLocalized().StartsWith("{locale}/"));
        }
        [TestMethod]
        public void GetDefaultsTest()
        {
            var r = new UnitTestRoute1();

            Assert.IsNotNull(r.GetDefaults());
        }
        [TestMethod]
        public void GetConstraintsTest()
        {
            var r = new UnitTestRoute1();

            Assert.IsNull(r.GetConstraints());
        }
        [TestMethod]
        public void GetConstraintsLocalizedTest()
        {
            var r = new UnitTestRoute1();

            Assert.IsNull(r.GetConstraintsLocalized());
        }
        [TestMethod]
        public void GetNamespacesTest()
        {
            var r = new UnitTestRoute1();

            Assert.IsNull(r.GetNamespaces());
        }
        [TestMethod]
        public void MakeTheSameAsTest()
        {
            var r = new UnitTestRoute1();
            var r2 = new UnitTestRoute1();

            r.Locale = "de-DE";
            r.Area = "a";
            r.Controller = "c";
            r.Action = "at";

            Assert.AreNotEqual(r.Locale, r2.Locale);
            Assert.AreNotEqual(r.Area, r2.Area);
            Assert.AreNotEqual(r.Controller, r2.Controller);
            Assert.AreNotEqual(r.Action, r2.Action);

            r2.MakeTheSameAs(r);

            Assert.AreEqual(r.Locale, r2.Locale);
            Assert.AreEqual(r.Area, r2.Area);
            Assert.AreEqual(r.Controller, r2.Controller);
            Assert.AreEqual(r.Action, r2.Action);
        }
        [TestMethod]
        public void GetSetDomainTest()
        {
            var r = new UnitTestRoute1();
            r.SetDomain("microsoft.com");

            Assert.AreEqual("microsoft.com", r.GetDomain());
        }
        [TestMethod]
        public void GetSetProtocolTest()
        {
            var r = new UnitTestRoute1();
            var pp = Enum.GetValues(typeof(BaseRoute.UrlProtocol));
            foreach (BaseRoute.UrlProtocol p in pp)
            {
                r.SetProtocol(p);
                Assert.AreEqual(p, r.GetProtocol());
            }
        }
        [TestMethod]
        public void GetSetPortTest()
        {
            var r = new UnitTestRoute1();
            for (int i = 1; i < 65536; i++)
            {
                r.SetPort(i);
                Assert.AreEqual(i, r.GetPort());
            }
        }
    }
}